package com.example.lcode.backtrack;

import java.util.ArrayList;
import java.util.List;

public class Question967 {

    public int[] numsSameConsecDiff(int n, int k) {
        List<Integer> res = new ArrayList<>();
        String str = "";
        numsSameConsecDiff(res, n, k, str);
        int [] arr = new int[res.size()];
        for (int i = 0; i < res.size(); i++) {
            arr[i] = res.get(i);
        }
        return arr;
    }

    private void numsSameConsecDiff(List<Integer> res, int numLenth, int distance, String str) {
        if (str.length() >= 2) {
            String lastFirst = str.substring(str.length() - 1);
            String lastSecond = str.substring(str.length() - 2, str.length() - 1);
            if (Math.abs(Integer.valueOf(lastFirst) - Integer.valueOf(lastSecond)) != distance) {
                return;
            } else {
                if (str.length() == numLenth) {
                    res.add(Integer.valueOf(str));
                    return;
                }
            }
        }
        for (int i = 0; i <= 9 ; i++) {
            if (str.startsWith("0") && str.length() == 1) {
                continue;
            }
            numsSameConsecDiff(res, numLenth, distance, str + i);
        }
    }

    public static void main(String[] args) {

        Question967 question967 = new Question967();
        int[] ints = question967.numsSameConsecDiff(2, 2);
        System.out.println(ints);

    }


}
